package cn.wolfcode.crm.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.github.pagehelper.PageInfo;

import cn.wolfcode.crm.domain.SystemDictionary;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ISystemDictionaryService;
import cn.wolfcode.crm.util.RequiredPermission;

@Controller
@RequestMapping("/systemDictionary")
public class SystemDictionaryController {
	@Autowired
	private ISystemDictionaryService systemDictionaryService;

	@RequiredPermission({"字典目录列表", "systemDictionary:list"})
	@RequestMapping("/list")
	public String list(@ModelAttribute("qo") QueryObject qo, Model model) {
		PageInfo<SystemDictionary> pageInfo = systemDictionaryService.list(qo);
		model.addAttribute("pageInfo", pageInfo);
		return "systemDictionary/list";
	}

	@RequiredPermission({"字典目录编辑", "systemDictionary:input"})
	@RequestMapping("/input")
	public String input(Long id, Model model) {
		if (id != null) {
			model.addAttribute("entity", systemDictionaryService.get(id));
		}
		return "systemDictionary/input";
	}

	@RequiredPermission({"字典目录新增/更新", "systemDictionary:saveOrUpdate"})
	@RequestMapping("/saveOrUpdate")
	public String saveOrUpdate(SystemDictionary entity) {
		systemDictionaryService.saveOrUpdate(entity);
		return "redirect:/systemDictionary/list.do";
	}
	
	@RequiredPermission({"字典目录删除", "systemDictionary:delete"})
	@RequestMapping("/delete")
	public String delete(@RequestParam("id") Long id) {
		if (id != null) {
			systemDictionaryService.delete(id);
		}
		return "redirect:/systemDictionary/list.do";
	}
}
